package ar.com.digitalbricks.view.imprenta.cliente.action;

import java.util.Collection;

import ar.com.digitalbricks.view.imprenta.helper.ClienteView;
import ar.com.digitalbricks.view.imprenta.helper.ContactoView;

import com.opensymphony.xwork2.Action;

public class CrearCliente extends ClienteAction {
	
	@SuppressWarnings("unchecked")
	public String execute() throws Exception {
		this.getClienteView().setContactos((Collection<ContactoView>) session.get("contactos"));
		Integer id = this.getClienteMgr().crearCliente(this.getClienteView());
		this.getClienteView().setId(id);
		this.getCurrentTransaction().commit();
		return Action.SUCCESS;
	}
	
	public String preparar() throws Exception {
		this.setClienteView(new ClienteView());
		if(session.containsKey("contactos")){session.remove("contactos");};
		this.setShowContacto(false);
		return Action.INPUT;
	}
}